package com.suhuamo.stream;

import java.util.ArrayList;
import java.util.List;

// 通过匿名内部类来存储我们想要执行的方法
public class E4 {

    List<Interface1> myMethodList = new ArrayList<>();

    public static void main(String[] args) {
        E4 e4 = new E4();

        e4.e4AddMethod(new Interface1() {
            @Override
            public void method1() {
                System.out.println("method1");
            }
        });

        e4.e4AddMethod(new Interface1() {
            @Override
            public void method1() {
                System.out.println("method2");
            }
        });

        e4.e4AddMethod(new Interface1() {
            @Override
            public void method1() {
                System.out.println("method3");
            }
        });

        e4.e4ExecMethod();

    }

    void e4AddMethod(Interface1 interface1) {
        myMethodList.add(interface1);
    }

    void e4ExecMethod() {
        for (Interface1 interface1 : myMethodList) {
            interface1.method1();
        }
    }
}
